package com.mud.mudcommune.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mud.mudcommune.R;
import com.mud.mudcommune.entry.VrEntry;
import com.mud.mudcommune.utils.ACache;
import com.mud.mudcommune.utils.LogUtils;

import java.util.List;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/2/18 0018.
 */

public class VRAdapter extends MyBaseAdapter {
    private static final String TAG = VRAdapter.class.getSimpleName();
    private List list;
    private ACache mCache;
    private Context context;

    public VRAdapter(Context context, @NonNull List list) {
        super(list);
        this.list = list;
        this.context = context;
        if(context!=null){
            mCache = ACache.get(context);
        }
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        VrEntry vrEntry = (VrEntry) list.get(position);
        VRAdapter.ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.case_item, null);
            viewHolder = new VRAdapter.ViewHolder(view);
        } else {
            viewHolder = (VRAdapter.ViewHolder) view.getTag();
        }
        LogUtils.i(TAG, vrEntry.getVrUrl() + "");
        Glide.with(context)
                .load(vrEntry.getVrImg())
                .into(viewHolder.casePic);
        viewHolder.caseName.setText(vrEntry.getVrName());
        return view;
    }

    static class ViewHolder {
        ImageView casePic;
        TextView caseName;

        public ViewHolder(View view) {
            casePic = ButterKnife.findById(view, R.id.case_pic);
            caseName = ButterKnife.findById(view, R.id.case_name);
            view.setTag(this);
        }
    }
}
